/**
* @file SourceListReader.cpp
* Class to handle interpolatable time serial data
*/

//============================================================================
//
//  Shoujian Zhang, Wuhan University, 2013
//
//============================================================================

#include "StringUtils.hpp"
#include "SourceListReader.hpp"
#include "MiscMath.hpp"
#include "CommonTime.hpp"
#include "MJD.hpp"
#include <fstream>

using namespace std;
using namespace gpstk::StringUtils;

#define debug 0

namespace gpstk
{

   void SourceListReader::loadFile(std::string file)
      noexcept(false)
   {

      ifstream inpf(file.c_str());
      if(!inpf)
      {
         FileMissingException fme("Could not open sourcelist file " + file);
         GPSTK_THROW(fme);
      }

         // Now, read the leap second data
      while(!inpf.eof() && inpf.good())
      {
         string line;
         getline(inpf,line);
         StringUtils::stripTrailing(line,'\r');

         if( inpf.eof() ) break;
         if( inpf.bad() ) break;

         if(debug)
         {
            cout << "line:" << line << endl;
         }

            // Jump the header!
         if(line[0] == '#') continue;

            // Define a string stream to read 'line'
         istringstream istrm(line);

         string srcName, isAtomic;

            // Get the variable values from stream
         istrm >> srcName >> isAtomic;

         SourceID source;
         transform(srcName.begin(), srcName.end(), srcName.begin(), ::toupper);
         source = SourceID(SourceID::Mixed, srcName);

         if(debug) cout << source << endl;
         sourceSet.insert(source);

      }

      inpf.close();

   }


   SourceIDSet SourceListReader::getSourceSet() const
      noexcept(false)
   {
       return sourceSet;

   }  // End of method 'SourceListReader::getLeapSec()'


}  // End of namespace gpstk
